﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using RxjhServer.Network;

namespace RxjhServer
{
	public partial class NetSet : Form
	{
		private TcpServer Server;

		public NetSet(TcpServer server)
		{
			this.InitializeComponent();
			this.Server = server;
		}

		private void NetSet_Load(object sender, EventArgs e)
		{
			if (this.Server.SendPolicy == SendPolicy.Pack)
			{
				this.radioButton1.Checked = true;
			}
			else if (this.Server.SendPolicy == SendPolicy.Safe)
			{
				this.radioButton2.Checked = true;
			}
			else
			{
				this.radioButton3.Checked = true;
			}
			if (this.Server.MarkSilence)
			{
				this.checkBox1.Checked = true;
			}
			else
			{
				this.checkBox1.Checked = false;
			}
			this.textBox1.Text = this.Server.WorkerThreadCount.ToString();
			this.textBox2.Text = this.Server.AcceptSocketCount.ToString();
			this.textBox3.Text = this.Server.SocketBufferSize.ToString();
			this.textBox4.Text = this.Server.SocketListenQueue.ToString();
			this.textBox5.Text = this.Server.FreeSocketObjLockTime.ToString();
			this.textBox6.Text = this.Server.FreeSocketObjPool.ToString();
			this.textBox9.Text = this.Server.FreeSocketObjHold.ToString();
			this.textBox8.Text = this.Server.FreeBufferObjPool.ToString();
			this.textBox7.Text = this.Server.FreeBufferObjHold.ToString();
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (this.checkBox1.Checked)
			{
				this.Server.MarkSilence = true;
				return;
			}
			this.Server.MarkSilence = false;
		}

		private void button1_Click(object sender, EventArgs e)
		{
			try
			{
				this.Server.WorkerThreadCount = uint.Parse(this.textBox1.Text);
				this.Server.AcceptSocketCount = uint.Parse(this.textBox2.Text);
				this.Server.SocketBufferSize = uint.Parse(this.textBox3.Text);
				this.Server.SocketListenQueue = uint.Parse(this.textBox4.Text);
				this.Server.FreeSocketObjLockTime = uint.Parse(this.textBox5.Text);
				this.Server.FreeSocketObjPool = uint.Parse(this.textBox6.Text);
				this.Server.FreeSocketObjHold = uint.Parse(this.textBox9.Text);
				this.Server.FreeBufferObjPool = uint.Parse(this.textBox8.Text);
				this.Server.FreeBufferObjHold = uint.Parse(this.textBox7.Text);
				MessageBox.Show("设置成功。");
			}
			catch
			{
			}
		}

		private void radioButton1_MouseClick(object sender, MouseEventArgs e)
		{
			this.Server.SendPolicy = SendPolicy.Pack;
		}

		private void radioButton2_MouseClick(object sender, MouseEventArgs e)
		{
			this.Server.SendPolicy = SendPolicy.Safe;
		}

		private void radioButton3_MouseClick(object sender, MouseEventArgs e)
		{
			this.Server.SendPolicy = SendPolicy.Direct;
		}
	}
}
